package br.com.hotel.entity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.NamedQuery;
@Entity
@NamedQuery(name="Preco.findAll", query="SELECT  p FROM Preco p WHERE p.service.Id=?1 AND p.tabelaPreco.dataInicial<= ?2 AND p.tabelaPreco.dataFinal>= ?3")
public class Preco {
	@Id
	@GeneratedValue
	private Long Id;
	public Preco() {
		// TODO Auto-generated constructor stub
	}
	
	public Preco(Long id, Double valor, TabelaPreco tp, Service s) {
		this.service =s;
		this.Id = id;
		this.valor = valor;
		this.tabelaPreco = tp;
	}

	@ManyToOne(cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
	@JoinColumn(name="service_id", referencedColumnName="id")
    private Service service;
	
	@Column(precision=2,nullable=false)
	private Double valor;
	
	@ManyToOne(cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
	@JoinColumn(name="tabela_preco_id", referencedColumnName="id")
	private TabelaPreco tabelaPreco;
	
	
	public Long getId() {
		return Id;
	}
	public void setId(Long id) {
		Id = id;
	}
	
	public TabelaPreco getTabelaPreco() {
		return tabelaPreco;
	}
	public void setTabelaPreco(TabelaPreco tabelaPreco) {
		this.tabelaPreco = tabelaPreco;
	}
	public Service getService() {
		return service;
	}
	public void setService(Service service) {
		this.service = service;
	}
	public Double getValor() {
		return valor;
	}
	public void setValor(Double valor) {
		this.valor = valor;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((Id == null) ? 0 : Id.hashCode());
		result = prime * result + ((service == null) ? 0 : service.hashCode());
		result = prime * result
				+ ((tabelaPreco == null) ? 0 : tabelaPreco.hashCode());
		result = prime * result + ((valor == null) ? 0 : valor.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Preco other = (Preco) obj;
		if (Id == null) {
			if (other.Id != null)
				return false;
		} else if (!Id.equals(other.Id))
			return false;
		if (service == null) {
			if (other.service != null)
				return false;
		} else if (!service.equals(other.service))
			return false;
		if (tabelaPreco == null) {
			if (other.tabelaPreco != null)
				return false;
		} else if (!tabelaPreco.equals(other.tabelaPreco))
			return false;
		if (valor == null) {
			if (other.valor != null)
				return false;
		} else if (!valor.equals(other.valor))
			return false;
		return true;
	}
	
	
	
}
